package cn.java79.springcore.printerano;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * @author oldliu
 * @since 1.0
 */
//纸张
@Service("A4")
public class TextPaper {
    //一行几个字，和一页多少行
    @Value("10")
    private int linewords;
    @Value("14")
    private int pagelines;

    public void print(String content){
        char[] cr = content.toCharArray();
        int l=0,w=0,p=0;//w记录当前行打了几个字，
        // l当前页打了几行，p当前的页号
        for(char c:cr){
            System.out.print(c);
            w++;
            if(w>=linewords){
                System.out.println();
                l++;
                w=0;
                if(l>=pagelines){
                    l=0;
                    ++p;
                    System.out.println("--"+p+"--");
                }
            }
        }
        if(l>0||w>0){
            System.out.println("\n--"+(++p)+"--");
        }
    }

    public int getLinewords() {
        return linewords;
    }

    public void setLinewords(int linewords) {
        this.linewords = linewords;
    }

    public int getPagelines() {
        return pagelines;
    }

    public void setPagelines(int pagelines) {
        this.pagelines = pagelines;
    }

    @Override
    public String toString() {
        return "纸张{" +
                "一行几个字：" + linewords +
                ", 一页多少行:" + pagelines +
                '}';
    }
}
